//
// Created by Scave on 2023/11/13.
//

#ifndef RIDER3D_RENDERER_H
#define RIDER3D_RENDERER_H

#include "Define.h"
#include "shader/Shader.h"
#include "shader/ShaderProgram.h"
#include "context/RenderContext.h"
#include "RenderNode.h"

NS_RIDER_BEGIN

    class Renderer {
    public:
        explicit Renderer(const SMART_PTR<RenderContext>& context);

        virtual void Render(SMART_PTR<RenderNode> node) = 0;

    protected:
        SMART_PTR<RenderContext> context_;
        SMART_PTR<ShaderProgram> program_;

        static UInt64 RenderTypeToBgfxState(RenderType type);
    };

    class MeshRenderer : public Renderer {
    public:
        explicit MeshRenderer(const SMART_PTR<RenderContext>& context);

        void Render(SMART_PTR<RenderNode> node) override;

    private:
        float vec4_camera_pos_[4] = {0};
        float vec4_material_params_[4] = {0};
        float vec4_ambient_color_[4] = {0};
        float vec4_arr_lights_[MAX_LIGHTS * 6][4];
        float vec4_light_count_[4] = {0};

        void SetShaderParams(SMART_PTR<StandardRenderNode>& node);
        void SetLightsInternal(SMART_PTR<StandardRenderNode>& node);
    };

    class SpriteRenderer : public Renderer {
    public:
        explicit SpriteRenderer(const SMART_PTR<RenderContext>& context);

        void Render(SMART_PTR<RenderNode> node) override;

    private:
    };

    class CanvasRenderer : public Renderer {
    public:
        explicit CanvasRenderer(const SMART_PTR<RenderContext>& context);

        void Render(SMART_PTR<RenderNode> node) override;
    };

NS_RIDER_END

#endif //RIDER3D_RENDERER_H
